<template>
	<view class="page">
		<view class="uni-product-list">
			<view class="uni-product" v-for="(product,index) in productList" :key="index" @click="godetails(product.id)">
				<view class="image-view">
					<image class="uni-product-image" :src="baseURL+product.cover_pic"></image>
				</view>
				<view class="uni-product-title">{{product.name}}</view>
				<view class="uni-product-price">
					<text class="uni-product-price-favour">￥{{product.price}}</text>
					<text class="uni-product-price-original">￥{{product.original_price}}</text>
					<!-- <text class="uni-product-tip">{{product.tip}}</text> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
    data() {
        return {
			baseURL:this.$API.baseURL,
			productList: [],
            page:1,
            rows:10,
			keyword:'',
        };
    },
	onLoad(e){
		this.keyword = e.keyword;
		this.mMallGoods();
	},
	onPullDownRefresh() {
		this.page = 1;
		this.productList = []
		this.mMallGoods('refresh');
	},
	onReachBottom(){
		this.page ++;
	    this.mMallGoods();
	},
    methods: {
		//请求列表
		mMallGoods(action){
			var _this = this;
			uni.request({
				url:this.$API.mMallGoods,
				method:"POST",
				data:{page:this.page,rows:this.rows,where:"{name:'"+encodeURIComponent(this.keyword)+"'}"},
				header:this.$API.get_head(),
				success: (res) => {
					var data = res.data.rows;
					if(action == 'refresh'){
						_this.productList = data;
						uni.stopPullDownRefresh();
					}else{
						data.forEach(item => {
						    _this.productList.push(item);
						});
					}
				},
				fail: () => {
					uni.stopPullDownRefresh();
					uni.showToast({
						title:"加载失败",
						icon:'none'
					})
				}
			})
		},
		godetails(id){
			uni.navigateTo({
				url:`/pages/shopPages/goods/detail/detail?id=`+id,
				// url:`/pages/shop/Goods_details`,
			})
		}
    },
};
</script>

<style>
	
</style>
